package cn.silver.framework.openapi.model;

import cn.silver.framework.openapi.constant.ResultEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author Silver Zhou
 */

@Data
@NoArgsConstructor
@Schema(name = "ResultTree", description = "树查询返回对象")
public class ResultTree<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 消息状态码
     */
    @Schema(title = "响应码")
    private int code;

    /**
     * 消息内容
     */
    @Schema(title = "响应消息")
    private String msg;

    /**
     * 列表数据
     */
    @Schema(title = "树结构数据")
    private List<T> data;

    @Schema(title = "树结构展开ids")
    private List<String> keys;

    public static <T> ResultTree<T> build() {
        ResultTree<T> rspData = new ResultTree<>();
        rspData.setCode(ResultEnum.SUCCESS.getCode());
        rspData.setMsg("查询成功");
        return rspData;
    }

    public static <T> ResultTree<T> build(List<T> list) {
        ResultTree<T> result = new ResultTree<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg("查询成功");
        result.setData(list);
        return result;
    }
}
